﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DingChiServiceApp.db
{
    public class LocalConfigJsonDao: JsonDao<LocalConfig>
    {
        private static LocalConfigJsonDao _instance;
        public static LocalConfigJsonDao Instance
        {
            get
            {
                if(_instance == null)
                {
                    _instance = new LocalConfigJsonDao();
                }
                return _instance;
            }
        }

        public LocalConfig GetLocalConfig()
        {
            var config = FindById(1);
            if(config == null)
            {
                config = new LocalConfig()
                {
                    baseUrl = GlobalConstract.BASE_URL,
                    id = 1,
                    createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    updateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    dataSource = "WIN-39MIV2AMP14\\SQLEXPRESS",
                    dbName = "dingchi",
                    userID = "sa",
                    port = 1433,
                    pwd = "local@1234",
                    maxRows = 5,
                    interval = 10,
                    StartDateTime= "2022-01-01 00:00:01"            
                };
                Insert(config);
                SyncUpdateToFile();
            }
            return config;
        }

    }
}
